/**
 * Created by smp on 2017/5/5.
 */
var modelPath=ROOT_PATH+'/majorHazard/deviceLocation/';
$('#unitId').combotree({
    url: ROOT_PATH+'/permission/department/getDepartmentTree.shtml?parentId=0',
    onSelect:function(node){
        $('#unitName').val(node.text);
        $("#unitCode").textbox("setValue",node.attributes.code);
    }
});
//表单提交
$('#btn_save').on('click',function () {
    var index=layer.confirm('是否确定保存？', {
        btn: ['确定','取消'] //按钮
    }, function(){
        $.ajax({
            type: "POST",
            url: modelPath+'judgement.shtml',
            data: {id:$(':input[name=id]').val(),code:$(':input[name=code]').val()},
            dataType: "json",
            success: function(result){
                if (result.success) {
        $('#form1').form('submit', {
            url: modelPath+'edit.shtml',

            onSubmit: function (param) {
                var isValid = $(this).form('validate');
                if (!isValid) {
                    layer.close(index);
                    layer.msg("请正确填写表单")
                }
                return $(this).form('validate');
            },
            success: function (result) {
                result = $.parseJSON(result);
                if (result.success){
                    //$.messager.progress('close');	// 如果提交成功则隐藏进度条
                   layer.msg(result.message,{time:1000,icon:1},function () {
                        parent.layer.close(parent.layer.getFrameIndex(window.name));
                        $.getIframeWindow().$('#dg1').datagrid('load');
                    });
                }else {
                    //$.messager.progress('close');	// 如果提交成功则隐藏进度条
                    parent.layer.msg(result.message,{time:1000,icon:2});
                }
            }
        });
                }
                else {
                    layer.msg('编码重复', {
                        icon: 2,
                        time: 2000
                    });
                }
            }
        });
    });
});
